/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */
package com.joolun.cloud.weixin.admin.controller;

import com.iecg.api.dto.IecgWeixinTemplateDto;
import com.joolun.cloud.weixin.admin.service.WxTemplateService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import jodd.util.StringUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信账号配置
 *
 * @author JL
 * @date 2019-03-23 21:26:35
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/template")
public class WxTemplateController {

	private final WxTemplateService wxTemplateService;

	@SysLog("推送模板消息")
	@PostMapping("/send")
	@Inner
	public R send(@RequestBody IecgWeixinTemplateDto iecgWeixinTemplateDto) {
		String notice = iecgWeixinTemplateDto.getNotice();
		if(StringUtil.isEmpty(notice)){
			return R.failed();
		}
		String toOpenId = iecgWeixinTemplateDto.getToOpenId();
		if(StringUtil.isEmpty(toOpenId)){
			return R.failed();
		}
		wxTemplateService.send(Long.valueOf(notice), toOpenId, "5e1ed70c1a5a5926bed00c92");
		return R.ok();
	}
}
